package userlimitRequest

import (
	"arabApi/app/api/requests"
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
	"github.com/thedevsaddam/govalidator"
)

type UserRoleAdd struct {
	UserId  string `json:"user_id" form:"user_id" valid:"UserId"`
	RoleIds string `json:"role_ids" form:"role_ids" valid:"RoleIds"`
}

func checkRoleIds(f validator.FieldLevel) bool {

	//reg1 := regexp.MustCompile(`^[0-9],?`)
	return true
}

func CheckUserRoleAdd(data interface{}, c *gin.Context) string {
	// 自定义验证规则
	rules := govalidator.MapData{
		"UserId": []string{"required"},
		//"email": []string{"required"},
		"RoleIds": []string{"required,checkRoleIds"},
	}
	// 自定义验证出错时的提示
	messages := govalidator.MapData{
		"UserId": []string{
			"required:Id 不能为空",
		},
		"RoleIds": []string{
			"required:角色id 不能为空",
			"checkRoleIds:角色ID 格式错误",
		},
	}

	errs := requests.Validate1(data, rules, messages)
	return requests.GetOneErr(errs)
}
